import { REJECT_REASON_ENUMS, REVIEW_STATUS_ENUMS, REJECT_REASON_OPTIONS } from './config';
import { getRealtimeSpecModel } from '../../latentProduct/utils';

// 获取渲染驳回备注列
export const getRenderRejectNoteCol = clickHandler => ({
  title: '驳回备注',
  width: 120,
  render: (h, { row, index }) => {
    const specialItems = [REJECT_REASON_ENUMS.Product, REJECT_REASON_ENUMS.CategoryAndClassify]
    if (!specialItems.includes(row.reasonType)) return <span>{row.reasonNote}</span>
    return (
      <el-input
        value={row.reasonNote}
        size="mini"
        suffixIcon="el-icon-search"
        onFocus={() => { clickHandler(row, index) }}
      />
    )
  }
})

// 获取审核状态文本值
const getAuditStateStr = status => {
  if (status == REVIEW_STATUS_ENUMS.Pass) return '审核通过'
  if (status == REVIEW_STATUS_ENUMS.Reject) return '审核驳回'
  return ''
}

// 获取驳回原因文本值
export const getReasonTypeStr = type => {
  const reasonTypeLabels = REJECT_REASON_OPTIONS.reduce((value, item) => {
    value[item.value] = item.label
    return value
  }, {})
  return reasonTypeLabels[type] ?? ''
}

export const TABLE_COLUMNS = [
  {
    title: '审核状态',
    render: (h, { row }) => <span>{getAuditStateStr(row.auditState)}</span>
  },
  {
    title: '驳回原因',
    width: 120,
    render: (h, { row }) => <span>{getReasonTypeStr(row.reasonType)}</span>
  },
  {
    title: '驳回备注',
    key: 'reasonNote'
  },
  {
    title: 'SKU编码',
    key: 'skuNo',
  },
  {
    title: '末级分类',
    key: 'categoryName',
  },
  {
    title: '归类名称',
    key: 'classificationName',
  },
  {
    title: '税类代码',
    key: 'taxCateNo',
  },
  {
    title: '销售税率',
    key: 'taxRate',
  },
  {
    title: '品牌',
    key: 'brandName',
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '规格',
    // key: 'specModel',
    render: (h, { row }) => <span>{getRealtimeSpecModel(row)}</span>
  },
  {
    title: '材质',
    key: 'material',
  },
  {
    title: '规格属性',
    type: 'slot',
    slotName: 'specAttrs'
  },
  {
    title: '基本属性',
    type: 'slot',
    slotName: 'basicAttrs'
  },
  {
    title: '计量单位',
    key: 'unitName',
  },
  {
    title: '件装数量',
    key: 'pieceInfo',
  },
  {
    title: '包装清单',
    key: 'packageContents',
  },
  {
    title: '国标条形码 ',
    key: 'barcode',
  },
  {
    title: '经营模式',
    key: 'dealModeStr'
  },
  {
    title: '合作模式',
    key: 'cooperationModeStr',
  },
  {
    title: '厂家编码',
    key: 'factoryCode',
  },
  {
    title: '产地',
    key: 'producingAreaName',
  },
  {
    title: '最长边(cm)',
    key: 'edge1',
  },
  {
    title: '次长边(cm)',
    key: 'edge2',
  },
  {
    title: '最短边(cm)',
    key: 'edge3',
  },
  {
    title: '体积(m³)',
    key: 'volume',
  },
  {
    title: '重量(kg)',
    key: 'weight',
  },
  {
    title: '是否定制',
    key: 'canCustomStr',
  },
  {
    title: '特殊要求说明',
    key: 'note',
  },
  {
    title: '售卖平台',
    key: 'salePlatStr',
  },
  {
    title: '销售区域',
    key: 'saleAreaStr',
  },
  {
    title: '最小起售量',
    key: 'saleMin',
  },
  {
    title: '销售限制类型',
    key: 'saleResTypeStr',
  },
  {
    title: '到货周期',
    key: 'arrivalPeriod',
  },
  {
    title: '创建人',
    key: 'operName',
  },
  {
    title: '创建时间',
    key: 'opeTime',
  },
  {
    title: '创建人部门',
    key: 'operDeptName',
  },
  {
    title: '商品管理区域',
    key: 'manageAreaName',
  },
  {
    title: '图文完善状态',
    key: 'imageStatusStr',
    width: 120,
    type: 'slot',
    fixed: 'right'
  },
]

export const FOOTER_FIELDS = [
  { label: '单据号', prop: 'recordNo' },
  { label: '审核状态', prop: 'workflowStatusStr' },
  { label: '提交人', prop: 'creatorName' },
  { label: '提交时间', prop: 'createOpeTime' },
  { label: '提交部门', prop: 'creatorDeptName' },
]
